package com.ymatou.query.seller.trading.api.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.query.seller.trading.api.parameter.GetPackageDeliveryOrdersCountBean;
import com.ymatou.query.seller.trading.api.parameter.resp.GetPackageDeliveryOrdersCountResponse;
import com.ymatou.query.seller.trading.api.parameter.sp.Sp_GetPackageDeliveryOrdersCount;
import com.ymatou.query.seller.trading.api.service.GetPackageDeliveryOrdersCountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
/**
*查询国内段未发货的拼邮订单接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetPackageDeliveryOrdersCount{
	private static GetPackageDeliveryOrdersCountBean getpackagedeliveryorderscountBean;
	private static GetPackageDeliveryOrdersCountCall getpackagedeliveryorderscountCall_seller;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询国内段未发货的拼邮订单接口");
	}

	@Before
	public void caseUp() {
		getpackagedeliveryorderscountBean=new GetPackageDeliveryOrdersCountBean();
		getpackagedeliveryorderscountCall_seller=new GetPackageDeliveryOrdersCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getpackagedeliveryorderscountCall_seller.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@SuppressWarnings("rawtypes")
	private void ConstructResponse(GetPackageDeliveryOrdersCountResponse response){
		Sp_GetPackageDeliveryOrdersCount sp = new Sp_GetPackageDeliveryOrdersCount();
		sp.setSellerId(getpackagedeliveryorderscountBean.getSellerId());
		sp.setDomesticDelivered(getpackagedeliveryorderscountBean.getDomesticDelivered());
		sp.setTimeFrom(getpackagedeliveryorderscountBean.getTimeFrom());
		sp.setTimeTo(getpackagedeliveryorderscountBean.getTimeTo());
		List<Map> results = sp.execute();
		if(DataUtil.isNullOrEmpty(results)){
			response = new GetPackageDeliveryOrdersCountResponse();
		}else{
			for(Map result:results){
				if((boolean)result.get("shangou")==true){
					response.setShangouOrdersCount(DataUtil.Integerr.GetValueOrDefault(result.get("count")));
				}else{
					response.setSpotOrdersCount(DataUtil.Integerr.GetValueOrDefault(result.get("count")));
				}
			}
		}
		response.setTotalOrdersCount(response.getShangouOrdersCount()+response.getSpotOrdersCount());
	}
	
	private void verify(){
		GetPackageDeliveryOrdersCountResponse expectResponse = new GetPackageDeliveryOrdersCountResponse();
		ConstructResponse(expectResponse);
		GetPackageDeliveryOrdersCountResponse actualResponse = getpackagedeliveryorderscountCall_seller.getPackageDeliveryOrdersCountResponse();
		DataUtil.verifyEquals(expectResponse.getShangouOrdersCount(), actualResponse.getShangouOrdersCount(), "验证ShangouOrdersCount");
		DataUtil.verifyEquals(expectResponse.getSpotOrdersCount(), actualResponse.getSpotOrdersCount(), "验证SpotOrdersCount");
		DataUtil.verifyEquals(expectResponse.getTotalOrdersCount(), actualResponse.getTotalOrdersCount(), "验证TotalOrdersCount");
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPackageDeliveryOrdersCount_001() {
		Logger.start(true,"查询国内段未发货的拼邮订单成功");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			//int SellerId = 288484;
			getpackagedeliveryorderscountBean.setSellerId(SellerId);
			//表示国内物流还没发货
			getpackagedeliveryorderscountBean.setDomesticDelivered(false);
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-3);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(2);
			getpackagedeliveryorderscountBean.setTimeFrom(BeginTime);
			getpackagedeliveryorderscountBean.setTimeTo(EndTime);
			// seller 后台发送请求
			getpackagedeliveryorderscountCall_seller.setData(getpackagedeliveryorderscountBean);
			getpackagedeliveryorderscountCall_seller.callService();			
			Logger.comment("getpackagedeliveryorderscountCall_seller send:" + getpackagedeliveryorderscountCall_seller.getEntityString());
			Logger.comment("getpackagedeliveryorderscountCall_seller response:" + getpackagedeliveryorderscountCall_seller.getReturnData());
			// user 后台发送请求
			GetPackageDeliveryOrdersCountCall getpackagedeliveryorderscountCall=new GetPackageDeliveryOrdersCountCall();
			getpackagedeliveryorderscountCall.setData(getpackagedeliveryorderscountBean);
			getpackagedeliveryorderscountCall.callService();			
			Logger.comment("getpackagedeliveryorderscountCall send:" + getpackagedeliveryorderscountCall.getEntityString());
			Logger.comment("getpackagedeliveryorderscountCall response:" + getpackagedeliveryorderscountCall.getReturnData());
			Logger.verifyEquals(getpackagedeliveryorderscountCall.getString("Data"),getpackagedeliveryorderscountCall_seller.getString("Data"), "验证seller 后台跟user后台 同样请求返回数据一致");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPackageDeliveryOrdersCount_002() {
		Logger.start(true,"查询6个月前国内段未发货的拼邮订单成功");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			//int SellerId = 288484;
			getpackagedeliveryorderscountBean.setSellerId(SellerId);
			//表示国内物流还没发货
			getpackagedeliveryorderscountBean.setDomesticDelivered(false);
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-384);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(2);
			getpackagedeliveryorderscountBean.setTimeFrom(BeginTime);
			getpackagedeliveryorderscountBean.setTimeTo(EndTime);
			// seller 后台发送请求
			getpackagedeliveryorderscountCall_seller.setData(getpackagedeliveryorderscountBean);
			getpackagedeliveryorderscountCall_seller.callService();			
			Logger.comment("getpackagedeliveryorderscountCall_seller send:" + getpackagedeliveryorderscountCall_seller.getEntityString());
			Logger.comment("getpackagedeliveryorderscountCall_seller response:" + getpackagedeliveryorderscountCall_seller.getReturnData());
			// user 后台发送请求
			GetPackageDeliveryOrdersCountCall getpackagedeliveryorderscountCall=new GetPackageDeliveryOrdersCountCall();
			getpackagedeliveryorderscountCall.setData(getpackagedeliveryorderscountBean);
			getpackagedeliveryorderscountCall.callService();			
			Logger.comment("getpackagedeliveryorderscountCall send:" + getpackagedeliveryorderscountCall.getEntityString());
			Logger.comment("getpackagedeliveryorderscountCall response:" + getpackagedeliveryorderscountCall.getReturnData());
			Logger.verifyEquals(getpackagedeliveryorderscountCall.getString("Data"),getpackagedeliveryorderscountCall_seller.getString("Data"), "验证seller 后台跟user后台 同样请求返回数据一致");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}